﻿using System;
using System.Collections.Generic;
using System.Data.Common;
using System.Linq;
using System.Linq.Expressions;
using System.Text;
using System.Threading.Tasks;
using LZH.DAL;
using LZH.Models;

namespace LZH.BLL
{
    public class BaseBLL<T> : LZH.Models.BaseEntity where T : BaseEntity, new()
    {
        private DAL<T> dao = null;
        public DAL<T> Dao
        {
            get
            {
                if (dao == null)
                {
                    throw new Exception("DAO is not implament");
                }
                return dao;
            }
        }

        public BaseBLL()
        {
            dao = new DAL<T>();
        }


        public  int Insert(T t)
        {
            return Dao.Insert(t);
        }
        public  int Insert(List<T> entities)
        {
            return Dao.Insert(entities);

        }
        public  int Update(T t)
        {
            return Dao.Update(t);
        }
        public  IQueryable<T> IQueryable()
        {
            return Dao.IQueryable();
        }
        public  IQueryable<T> IQueryable(Expression<Func<T, bool>> predicate)
        {
            return Dao.IQueryable(predicate);
        }

        public  IQueryable<T> IQueryable(Expression<Func<T, bool>> predicate, int pageIndex, int pageSize = 10)
        {
            return Dao.IQueryable(predicate, pageIndex, pageSize);
        }
        public  T FindEntity(string id)
        {
            return Dao.FindEntity(id);
        }


        public IQueryable<T> LoadPageItems<Tkey>(int pageSize, int pageIndex, out  int total, Expression<Func<T, bool>> whereLambda, Func<T, Tkey> orderbyLambda, bool isAsc)

        {
            return Dao.LoadPageItems(pageSize, pageIndex, out total, whereLambda, orderbyLambda, isAsc);
        }
        
        public  int Delete(T entity)
        {
            return Dao.Delete(entity);
        }
        public  int Delete(Expression<Func<T, bool>> predicate)
        {
            return Dao.Delete(predicate);
        }

        public int Delete(List<T> entitys)
        {
            return Dao.Delete(entitys);
        }

        public  List<T> FindList(string strsql)
        {
            return Dao.FindList(strsql);
        }
        public  List<T> FindList(string strSql, DbParameter[] dbParametere)
        {
            return Dao.FindList(strSql, dbParametere);
        }
    }
}
